<?php
/**
 * Created by PhpStorm.
 * User: Min
 * Date: 2018/4/18
 * Time: 14:52
 */

namespace SDXApi\Model;


use Think\Model;

class SeminarTemplateTagGoodsModel extends Model
{
    /**
     * 获取标签商品列表
     * @author Min
     * @param $tag_id
     * @param $wid
     * @return bool
     */
    public function getTagGoodsList($tag_id, $wid)
    {

        if (empty($wid) || empty($tag_id)) {
            return false;
        }

        $where = array(
            'sg.tag_id'	=>	$tag_id,
            'g.is_delete'	=>	0,
            'g.is_on_sale'	=>	1,
            'g.original_img'=>	array(
                'NEQ',
                ''
            ),
        );

        $field = 'sg.goods_id,g.goods_name,g.goods_sn,g.goods_thumb,g.goods_img,g.goods_brief,g.is_presell,g.promote_price,g.promote_start_date,g.promote_end_date,g.goods_number,g.warn_number,g.original_img,g.is_on_sale,g.promote_goods_number,g.promote_today_number,g.is_buynow,g.spec_unit,g.spec_value,g.min_buy_num,g.delivery_type,g.delivery_cycle,gs.practical_num,sg.sort,g.is_promote';

        $data = $this
            ->alias('sg')
            ->field($field)
            ->join('LEFT JOIN __GOODS_WID_'. $wid .'__ AS g ON sg.goods_id = g.goods_id')
            ->join('LEFT JOIN __GOODS_STORAGE__ AS gs ON sg.goods_id = gs.goods_id AND gs.wid = ' . $wid)
            ->where($where)
            ->select();

        return $data;
    }

}